package com.ruoyi.district.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.district.domain.District;
import com.ruoyi.district.service.IDistrictService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 区管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-10
 */
@RestController
@RequestMapping("/district/district")
public class DistrictController extends BaseController
{
    @Autowired
    private IDistrictService districtService;

    /**
     * 查询区管理列表
     */
    @PreAuthorize("@ss.hasPermi('district:district:list')")
    @GetMapping("/list")
    public TableDataInfo list(District district)
    {
        startPage();
        List<District> list = districtService.selectDistrictList(district);
        return getDataTable(list);
    }

    /**
     * 导出区管理列表
     */
    @PreAuthorize("@ss.hasPermi('district:district:export')")
    @Log(title = "区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, District district)
    {
        List<District> list = districtService.selectDistrictList(district);
        ExcelUtil<District> util = new ExcelUtil<District>(District.class);
        util.exportExcel(response, list, "区管理数据");
    }

    /**
     * 获取区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('district:district:query')")
    @GetMapping(value = "/{districtId}")
    public AjaxResult getInfo(@PathVariable("districtId") Long districtId)
    {
        return success(districtService.selectDistrictByDistrictId(districtId));
    }

    /**
     * 新增区管理
     */
    @PreAuthorize("@ss.hasPermi('district:district:add')")
    @Log(title = "区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody District district)
    {
        return toAjax(districtService.insertDistrict(district));
    }

    /**
     * 修改区管理
     */
    @PreAuthorize("@ss.hasPermi('district:district:edit')")
    @Log(title = "区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody District district)
    {
        return toAjax(districtService.updateDistrict(district));
    }

    /**
     * 删除区管理
     */
    @PreAuthorize("@ss.hasPermi('district:district:remove')")
    @Log(title = "区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{districtIds}")
    public AjaxResult remove(@PathVariable Long[] districtIds)
    {
        return toAjax(districtService.deleteDistrictByDistrictIds(districtIds));
    }
}
